import { BasicColumn } from '/@/components/Table';
import { FormSchema } from '/@/components/Table';
import { projectSimple } from '/@/api/backs/foundation/foundation';
import { deptSimple } from '/@/api/backs/salary/salary';

export const columns: BasicColumn[] = [
  {
    title: '规则名称',
    dataIndex: 'name',
  },
  {
    title: '项目',
    dataIndex: 'projectName',
    customRender: ({ record }) => {
      return record.projectName || '--';
    },
  },
  {
    title: '部门',
    dataIndex: 'deptName',
    customRender: ({ record }) => {
      return record.deptName || '--';
    },
  },
  {
    title: '考勤类型',
    dataIndex: 'attendanceTypeVal',
  },
  {
    title: '打卡地址',
    dataIndex: 'position',
    customRender: ({ record }) => {
      return record.attendRulePositionList[0].position;
    },
  },
  {
    title: '打卡半径',
    dataIndex: 'range',
    customRender: ({ record }) => {
      return record.attendRulePositionList[0].range + '米';
    },
  },
];

export const searchFormSchema: FormSchema[] = [
  {
    label: '考勤规则名称',
    field: 'name',
    component: 'Input',
    colProps: { span: 8 },
    componentProps: ({ tableAction }) => {
      return {
        onPressEnter: () => {
          const { reload } = tableAction;
          reload();
        },
      };
    },
  },
  {
    label: '项目名称',
    field: 'projectName',
    component: 'Input',
    colProps: { span: 8 },
    componentProps: ({ tableAction }) => {
      return {
        onPressEnter: () => {
          const { reload } = tableAction;
          reload();
        },
      };
    },
  },
  {
    label: '部门名称',
    field: 'deptName',
    component: 'Input',
    colProps: { span: 8 },
    componentProps: ({ tableAction }) => {
      return {
        onPressEnter: () => {
          const { reload } = tableAction;
          reload();
        },
      };
    },
  },
   {
    field: 'attendanceType',
    label: '考勤类型',
    component: 'Select',
    colProps: { span: 8 },
    componentProps: {
      options:[{
        label:"固定考勤",
        value:"FIXED_ATTENDANCE"
      },
      {
        label:"自由考勤",
        value:"FREEDOM_ATTENDANCE"
      }]
    },
  },
];

export const formSchema: FormSchema[] = [
  {
    label: '规则名称',
    field: 'name',
    component: 'Input',
    required: true,
    componentProps: {
      placeholder: '请输入规则名称',
    }
  },
  {
    field: 'type',
    label: '菜单类型',
    component: 'RadioButtonGroup',
    defaultValue: 1,
    componentProps: {
      options: [
        { label: '项目', value: 1 },
        { label: '部门', value: 2 },
      ],
    },
    colProps: { lg: 12, md: 24 },
    required: true,
    dynamicDisabled:({values})=>values.propsType=='add' ? false : true
  },
  {
    label: '项目',
    field: 'projectId',
    component: 'ApiSelect',
    ifShow: ({ values }) => values.type == 1,
    dynamicDisabled:({values})=>values.propsType=='add' ? false : true,
    required: ({ values }) => (values.deptId && values.deptId.length ? false : true),
    componentProps: {
      api:projectSimple,
      placeholder: '请选择指定项目',
      labelField: 'name',
      valueField: 'id',
      getPopupContainer: () => document.body,
      showSearch: true,
      filterOption: (input, option) => {
        return option.label.toLowerCase().indexOf(input.toLowerCase()) >= 0;
      },
    },
    
  },
  {
    field: 'deptId',
    label: '部门',
    ifShow: ({ values }) => values.type == 2,
    dynamicDisabled:({values})=>values.propsType=='add' ? false : true,
    component: 'ApiTreeSelect',
    componentProps: (values) => {
      return {
        placeholder: '请选择指定部门',
        api: deptSimple,
        labelField: 'name',
        valueField: 'id',
        dropdownStyle: { maxHeight: '400px', overflow: 'auto' },
        replaceFields: {
          children: 'children',
          title: 'name',
          key: 'id',
          value: 'id',
        },
      }
    },
  },
  {
    field: 'attendanceType',
    label: '规则类型',
    component: 'RadioGroup',
    required: true,
    slot: 'attendanceType',
    defaultValue: 'FIXED_ATTENDANCE',
    colProps: { lg: 24, md: 24 },
  },
  {
    field: 'workDay',
    label: '设置工作日',
    component: 'CheckboxGroup',
    ifShow: false,
  },
  {
    field: 'formData',
    label: '地址',
    component: 'Input',
    required: true,
    slot: 'addressShow',
    colProps: { lg: 24, md: 24 },
  },
];
